package vip.liux.backend.adapter.web;

import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;
import vip.liux.application.dots.PagedResultDto;
import vip.liux.backend.application.service.coupon.CouponDto;
import vip.liux.backend.application.service.coupon.CouponService;
import vip.liux.backend.application.service.coupon.CreateCouponDto;
import vip.liux.backend.application.service.coupon.QueryCouponDto;

@RestController
@RequestMapping("/api/coupon")
public class CouponController {

    private final CouponService couponService;

    public CouponController(CouponService couponService) {
        this.couponService = couponService;
    }

    /**
     * 创建优惠券
     *
     * @param createCouponDto 创建优惠券数据传输对象
     * @return 优惠券数据传输对象
     */
    @PostMapping
    public CouponDto create(@Valid @RequestBody CreateCouponDto createCouponDto) {
        return couponService.create(createCouponDto);
    }

    /**
     * 查询优惠券
     *
     * @param input 优惠券条件
     * @return 优惠券数据传输对象
     */
    @GetMapping("/list")
    public PagedResultDto<CouponDto> query(QueryCouponDto input) {
        return couponService.query(input);
    }

    /**
     * 优惠券详情
     *
     * @param id 优惠券id
     * @return 优惠券数据传输对象
     */
    @GetMapping("/{id}")
    public CouponDto detail(@PathVariable Long id) {
        return couponService.detail(id);
    }

    /**
     * 停用优惠券
     *
     * @param id 优惠券id
     */
    @PutMapping("/{id}/disable")
    public void disable(@PathVariable Long id) {
        couponService.disable(id);
    }

}